const axios = require("axios")
// const baseUrl = "http://musicapi.leanapp.cn"
// var baseUrl = "https://autumnfish.cn"
// const baseUrl = "http://www.yemengs.cn"
const base = "http://localhost:3000"

// 超时设定
axios.defaults.timeout = 15000;
axios.defaults.withCredentials = true;

//get 请求
export const getRequest = (url, params) => {
    return axios({
        method: 'get',
        url: `${base}${url}`,
        params: params,
        headers: {

        }
    });
};

// post请求
export const postRequest = (url, params) => {
    return axios({
        method: 'post',
        url: `${base}${url}`,
        data: params,
        transformRequest: [function (data) {
            let ret = '';
            for (let it in data) {
                ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&';
            }
            return ret;
        }],
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded',
        }
    });
};

// 文件导出
export const exportFileRequest = (url, params) => {
    return axios({
        method: 'get',
        url: `${base}${url}`,
        params: params,
        responseType: 'blob',
        headers: {
        }
    });
};
